package com.kwan.x_im.base;


import android.util.Log;

import com.jeremyliao.liveeventbus.LiveEventBus;
import com.kwan.x_im.data.IMViewMode;
import com.kwan.x_im.data.http.HttpEvent;
import com.kwan.x_im.main.mode.MainViewMode;
import com.kwan.xframe.mvvm.view.activity.BaseActivity;

import java.lang.reflect.ParameterizedType;

import androidx.databinding.ViewDataBinding;
import androidx.lifecycle.Observer;
import timber.log.Timber;

/**
 * @author kwan
 * @date 2023/2/20 10:26
 * @Describe
 */
public abstract class IMBaseActivity<V extends ViewDataBinding, M extends IMViewMode> extends BaseActivity<V> {

	public M mViewMode;

	@Override
	protected void initData() {
		Class<M> clz = (Class<M>) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
		Timber.e("initData IMViewMode ::" + clz);
		mViewMode = getActivityScopeViewModel(clz);
		getLifecycle().addObserver(mViewMode);
		LiveEventBus.get(HttpEvent.class)
				.observe(this, new Observer<HttpEvent>() {
					@Override
					public void onChanged(HttpEvent httpEvent) {
						Timber.e("onHttpResult:" + httpEvent.func + " Msg:" + httpEvent.getMsg());
						onHttpResult(httpEvent);
					}
				});
	}

	public abstract void onHttpResult(HttpEvent<?> httpEvent);
}
